{extend name="extra@admin/content"}
{block name="content"}
<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="__SELF__" data-auto="true" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券名字</label>
        <div class="layui-input-block">
            <input name="name" value='' required="required" 
                   title="优惠券名字" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">上传图片</label>
      <div style="position:relative">
          <div class="uploadimage"><input type="hidden" name="img"></div>
          <a data-file="one" data-field="img" data-type="png,jpg" data-uptype="local" href="javascript:void(0)" class="uploadbutton">上传图片</a>
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
          <input type="radio" name="type" value="1" lay-filter="test" title="通用优惠券">
          <input type="radio" name="type" value="0" lay-filter="test" title="商品优惠券">
        </div>
    </div>
     <div class="layui-form-item" id="goods_id" style="display:none;">
        <label class="layui-form-label">所属商品</label>
        <div class="layui-input-block">
             <span>
                   <select name="goods_id" lay-search>
                      {foreach($list as $v)}
                       <option value="{$v->id}"> {$v->name}</option>
                      {/foreach}
                   </select>
             </span>
        </div>
    </div>
    
    <div class="layui-form-item" id="condition" style="display:none;">
        <label class="layui-form-label">满减条件</label>
        <div class="layui-input-block">
            <input name="condition" value='' required="required" 
                   title="满减条件，例如：满300减30" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" id="money" style="display:none;">
        <label class="layui-form-label">优惠金额</label>
        <div class="layui-input-block">
            <input name="money" value='' required="required" 
                   title="代金金额" class="layui-input">
        </div>
    </div>
     <div class="layui-form-item" id="discount" style="display:none;">
        <label class="layui-form-label">折扣</label>
        <div class="layui-input-block">
            <input name="discount" value='' required="required" 
                   title="输入0~100的数字" class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">发放数量</label>
        <div class="layui-input-block">
            <input name="createnum" value='' required="required" 
                   title="使用条件，满减" class="layui-input">
        </div>
    </div>
     <!-- <div class="layui-form-item">
        <label class="layui-form-label">发放类型</label>
        <div class="layui-input-block">
             <span>
                   <select name="send_type">
                       <option value="0"> 无数量限制按时间发放</option>
                       <option value="1"> 按量按时间发放领完为止</option>
                   </select>
             </span>
        </div>
    </div> -->
    <div class="layui-form-item">
        <label class="layui-form-label">发放时间</label>
        <div class="layui-input-block">
            <input type="text" name="send_start_time"  class="layui-input" id="time1" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input type="text" name="send_end_time" class="layui-input" id="time2" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">使用开始时间</label>
        <div class="layui-input-block">
              <input type="text" name="use_start_time" class="layui-input" id="time3" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">使用结束时间</label>
        <div class="layui-input-block">
                <input  name="use_end_time"  type="text" class="layui-input" id="time4" placeholder="yyyy-MM-dd">
        </div>
    </div>
     <!-- <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
          <input type="radio" name="status" value="1"  title="有效" >
          <input type="radio" name="status" value="0"  title="无效" >
        </div>
    </div> -->
    
    <div class="hr-line-dashed"></div>
    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
    <script type="text/javascript">
        require(['jquery'], function () {
            $('[name="img"]').on('change', function () {
                $(this).parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + this.value + ')');
            });

            layui.use('laydate', function(){
              var laydate = layui.laydate;
              
              //执行一个laydate实例
              laydate.render({
                elem: '#time1' //指定元素
              });
              laydate.render({
                elem: '#time2' //指定元素
              });
              laydate.render({
                elem: '#time3' //指定元素
              });
              laydate.render({
                elem: '#time4' //指定元素
              });
            });
        });
    </script>
    <script>window.form.render();</script>
    <script type="text/javascript">
      form.on('radio(test)', function(data){
        if(data.value == 1){      //通用优惠券
          $('#goods_id').css('display','none');
          $('#condition').css('display','block');
          $('#money').css('display','block');
          $('#discount').css('display','none');
        }else if(data.value == 0){   //特定商品优惠券
          $('#goods_id').css('display','block');
          $('#condition').css('display','none');
          $('#money').css('display','none');
          $('#discount').css('display','block');
        }
      });
    </script>
</form>
<style type="text/css">  
.ibox-content{
    overflow-y: scroll;
    overflow-x: hidden;
    height: 500px;
}
</style>
{/block}

